

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

import javax.microedition.media.*;
import javax.microedition.media.control.*;

public class Mobil
    extends MIDlet
    implements PlayerListener {
   
    private Play play;
    private Display display;
    private static Player player;
    private VolumeControl vc;

   
    public Mobil() {
        display = Display.getDisplay(this);
    }

   
    public void startApp() {
        try {
            playMedia(null);
        } catch (Exception e) {
            e.printStackTrace();
        }
        play = new Play(this, display, player);
        play.setFullScreenMode(true);
        display.setCurrent(play);       
        new Thread(play).start();
    }

    public void pauseApp() {}

    public void destroyApp(boolean unconditional) {
        if(player != null){
            player.close();
        }
    }

   
    public void exitMIDlet() {
        destroyApp(false);
        notifyDestroyed();
    }

    private void playMedia(String file)
        throws Exception {
        player = Manager.createPlayer(getClass().getResourceAsStream(file), "audio/x-wav");
   
        player.addPlayerListener(this);
   
        player.setLoopCount(-1);
        player.prefetch();
        player.realize();
       
        vc = (VolumeControl)player.getControl("VolumeControl");
        if (vc != null)
            vc.setLevel(30);

   
        player.start();
    }

    public void playerUpdate(Player player, String event, Object eventData) {
        if(event.equals(PlayerListener.STARTED) &&
          new Long(0L).equals((Long)eventData)) {
        } else if(event.equals(PlayerListener.CLOSED)) {
        }
    }
};
